{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "xlyptNJ2ICnN"
      },
      "source": [
        "# SD Trainer Colab\n",
        "Colab NoteBook Created by [licyk](https://github.com/licyk)\n",
        "\n",
        "Jupyter Notebook 仓库：[licyk/sd-webui-all-in-one](https://github.com/licyk/sd-webui-all-in-one)\n",
        "\n",
        "这是适用于 [Colab](https://colab.research.google.com) 部署 [SD-Trainer](https://github.com/Akegarasu/lora-scripts) / [Kohya GUI](https://github.com/bmaltais/kohya_ss) 的 Jupyter Notebook，使用时请按顺序执行 Jupyter Notebook 单元。\n",
        "\n",
        "Colab 链接：<a href=\"https://colab.research.google.com/github/licyk/sd-webui-all-in-one/blob/main/sd_trainer_colab.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>\n",
        "\n",
        "\n",
        "## 功能\n",
        "1. 环境配置：配置安装的 PyTorch 版本、内网穿透的方式，并安装 SD Trainer。默认设置下已启用`配置环境完成后立即启动 SD Trainer`选项，则安装完成后将直接启动 SD Trainer，并显示访问地址。\n",
        "2. 下载模型：下载可选列表中的模型（可选）。\n",
        "3. 自定义模型下载：使用链接下载模型（可选）。\n",
        "4. 扩展下载：使用链接下载扩展（可选）。\n",
        "5. 启动 SD Trainer：启动 SD Trainer，并显示访问地址。\n",
        "\n",
        "\n",
        "## 使用\n",
        "1. 在 Colab -> 代码执行程序 > 更改运行时类型 -> 硬件加速器 选择`GPU T4`或者其他 GPU。\n",
        "2. `环境配置`单元中的选项通常不需要修改，保持默认即可。如需切换其他 SD Trainer 分支，可修改`环境配置`单元中的`SD Trainer 分支预设`选项。\n",
        "3. 运行`环境配置`单元，默认设置下已启用`配置环境完成后立即启动 SD Trainer`选项，则环境配置完成后立即启动 SD Trainer，此时将弹出 Google Drive 授权页面，根据提示进行操作。配置完成后将启动 SD Trainer，SD Trainer 的访问地址可在日志中查看。\n",
        "4. 如果未启用`配置环境完成后立即启动 SD Trainer`选项，需要运行`启动 SD Trainer`单元，此时将弹出 Google Drive 授权页面，根据提示进行操作。配置完成后将启动 SD Trainer，SD Trainer 的访问地址可在日志中查看。\n",
        "5. 提示词查询工具：[SD 绘画提示词查询](https://licyk.github.io/t/tag)\n",
        "\n",
        "\n",
        "## 提示\n",
        "1. Colab 在关机后将会清除所有数据，所以每次重新启动时必须运行`环境配置`单元才能运行`启动 SD Trainer`单元。\n",
        "2. [Ngrok](https://ngrok.com) 内网穿透在使用前需要填写 Ngrok Token，可在 [Ngrok](https://ngrok.com) 官网获取。\n",
        "3. [Zrok](https://zrok.io) 内网穿透在使用前需要填写 Zrok Token, 可在 [Zrok](https://docs.zrok.io/docs/getting-started) 官网获取。\n",
        "4. 每次启动 Colab 后必须运行`环境配置`单元，才能运行`启动 SD Trainer`单元启动 SD Trainer。\n",
        "5. 其他功能有自定义模型下载等功能，根据自己的需求进行使用。\n",
        "6. 运行`启动 SD Trainer`时将弹出 Google Drive 访问授权提示，根据提示进行授权。授权后，使用 SD Trainer 生成的图片将保存在 Google Drive 的`sd_trainer_output`文件夹中。\n",
        "7. 在`额外挂载目录设置`中可以挂载一些额外目录，如 LoRA 模型目录，挂载后的目录可在 Google Drive 的`sd_trainer_output`文件夹中查看和修改。可通过该功能在 Google Drive 上传模型并在 SD Trainer 中使用。\n",
        "8. 默认挂载以下目录到 Google Drive，可在 Google Drive 的`sd_trainer_output`文件夹中上传和修改文件：`outputs`, `output`, `config`, `train`, `logs`"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "VjYy0F2gZIPR"
      },
      "outputs": [],
      "source": [
        "#@title 👇 环境配置\n",
        "# SD WebUI All In One 功能初始化部分, 通常不需要修改\n",
        "# 如果需要查看完整代码实现, 可阅读: https://github.com/licyk/sd-webui-all-in-one/blob/main/sd_webui_all_in_one\n",
        "#################################################################################################################\n",
        "# SD_WEBUI_ALL_IN_ONE_URL, FORCE_DOWNLOAD_CORE 参数可根据需求修改, 通常保持默认即可\n",
        "SD_WEBUI_ALL_IN_ONE_URL = \"https://github.com/licyk/sd-webui-all-in-one@main\" # SD WebUI All In One 核心下载地址\n",
        "FORCE_DOWNLOAD_CORE = False # 设置为 True 时, 即使 SD WebUI All In One 已存在也会重新下载\n",
        "#################################################################################################################\n",
        "import os\n",
        "try:\n",
        "    _ = JUPYTER_ROOT_PATH  # type: ignore # noqa: F821\n",
        "except Exception:\n",
        "    JUPYTER_ROOT_PATH = os.getcwd()\n",
        "!python -c \"import sd_webui_all_in_one\" &> /dev/null && [ \"{FORCE_DOWNLOAD_CORE}\" != \"True\" ] || python -m pip install \"git+{SD_WEBUI_ALL_IN_ONE_URL}\"\n",
        "from sd_webui_all_in_one import logger, VERSION, SDTrainerManager\n",
        "logger.info(\"SD WebUI All In One 核心模块初始化完成, 版本: %s\", VERSION)\n",
        "\n",
        "#######################################################\n",
        "\n",
        "# SD Trainer 分支预设\n",
        "SD_TRAINER_BRANCH_PRESET_DICT = {\n",
        "    \"Akegarasu/SD-Trainer 分支\": {\n",
        "        \"url\": \"https://github.com/Akegarasu/lora-scripts\",\n",
        "        \"requirements\": \"requirements.txt\",\n",
        "        \"launch_args\": \"--skip-prepare-onnxruntime\",\n",
        "        \"webui_port\": 28000,\n",
        "    },\n",
        "    \"bmaltais/Kohya GUI 分支\": {\n",
        "        \"url\": \"https://github.com/bmaltais/kohya_ss\",\n",
        "        \"requirements\": \"requirements.txt\",\n",
        "        \"launch_args\": \"--inbrowser --language zh-CN --noverify\",\n",
        "        \"webui_port\": 7860,\n",
        "    },\n",
        "}\n",
        "\n",
        "#@markdown ## SD Trainer 核心配置选项\n",
        "#@markdown - SD Trainer 分支预设：\n",
        "SD_TRAINER_BRANCH_PRESET = \"Akegarasu/SD-Trainer 分支\" # @param [\"Akegarasu/SD-Trainer 分支\", \"bmaltais/Kohya GUI 分支\"]\n",
        "#@markdown - SD Trainer 分支仓库地址（可选，不填则使用分支预设值）：\n",
        "SD_TRAINER_REPO_OPT = \"\" #@param {type:\"string\"}\n",
        "#@markdown - SD Trainer 依赖表名（可选，不填则使用分支预设值）：\n",
        "SD_TRAINER_REQUIREMENTS_OPT = \"\" #@param {type:\"string\"}\n",
        "#@markdown - SD Trainer 启动参数（可选，不填则使用分支预设值）：\n",
        "SD_TRAINER_LAUNCH_ARGS_OPT = \"\" #@param {type:\"string\"}\n",
        "#@markdown - SD Trainer 访问端口（可选，不填则使用分支预设值）：\n",
        "SD_TRAINER_WEBUI_PORT_OPT = \"\" #@param {type:\"string\"}\n",
        "#@markdown ---\n",
        "#@markdown ## PyTorch 组件版本选项：\n",
        "#@markdown - PyTorch：\n",
        "PYTORCH_VER = \"torch==2.8.0+cu126 torchvision==0.23.0+cu126 torchaudio==2.8.0+cu126\" #@param {type:\"string\"}\n",
        "#@markdown - xFormers：\n",
        "XFORMERS_VER = \"xformers==0.0.32.post2\" #@param {type:\"string\"}\n",
        "#@markdown ---\n",
        "#@markdown ## 包管理器选项：\n",
        "#@markdown - 使用 uv 作为 Python 包管理器\n",
        "USE_UV = True #@param {type:\"boolean\"}\n",
        "#@markdown - PyPI 主镜像源\n",
        "PIP_INDEX_MIRROR = \"https://pypi.python.org/simple\" #@param {type:\"string\"}\n",
        "#@markdown - PyPI 扩展镜像源\n",
        "PIP_EXTRA_INDEX_MIRROR = \"https://download.pytorch.org/whl/cu126\" #@param {type:\"string\"}\n",
        "#@markdown - PyPI 额外镜像源\n",
        "PIP_FIND_LINKS_MIRROR = \"\" #@param {type:\"string\"}\n",
        "#@markdown - PyTorch 镜像源\n",
        "PYTORCH_MIRROR = \"https://download.pytorch.org/whl/cu126\" #@param {type:\"string\"}\n",
        "#@markdown ---\n",
        "#@markdown ## 内网穿透选项：\n",
        "#@markdown - 使用 remote.moe 内网穿透\n",
        "USE_REMOTE_MOE = True #@param {type:\"boolean\"}\n",
        "#@markdown - 使用 localhost.run 内网穿透\n",
        "USE_LOCALHOST_RUN = True #@param {type:\"boolean\"}\n",
        "#@markdown - 使用 pinggy.io 内网穿透\n",
        "USE_PINGGY_IO = True #@param {type:\"boolean\"}\n",
        "#@markdown - 使用 CloudFlare 内网穿透\n",
        "USE_CLOUDFLARE = True #@param {type:\"boolean\"}\n",
        "#@markdown - 使用 Gradio 内网穿透\n",
        "USE_GRADIO = True #@param {type:\"boolean\"}\n",
        "#@markdown - 使用 Ngrok 内网穿透（需填写 Ngrok Token，可在 [Ngrok](https://ngrok.com) 官网获取）\n",
        "USE_NGROK = True #@param {type:\"boolean\"}\n",
        "#@markdown - Ngrok Token\n",
        "NGROK_TOKEN = \"\"  #@param {type:\"string\"}\n",
        "#@markdown - 使用 Zrok 内网穿透（需填写 Zrok Token，可在 [Zrok](https://docs.zrok.io/docs/getting-started) 官网获取）\n",
        "USE_ZROK = True #@param {type:\"boolean\"}\n",
        "#@markdown - Zrok Token\n",
        "ZROK_TOKEN = \"\"  #@param {type:\"string\"}\n",
        "#@markdown ---\n",
        "#@markdown ## 快速启动选项：\n",
        "#@markdown - 配置环境完成后立即启动 SD Trainer（并挂载 Google Drive）\n",
        "QUICK_LAUNCH = True #@param {type:\"boolean\"}\n",
        "#@markdown - 不重复配置环境（当重复运行环境配置时将不会再进行安装）\n",
        "NO_REPEAT_CONFIGURE_ENV = True #@param {type:\"boolean\"}\n",
        "#@markdown ---\n",
        "#@markdown ## 其他选项：\n",
        "#@markdown - 清理无用日志\n",
        "CLEAR_LOG = True #@param {type:\"boolean\"}\n",
        "#@markdown - 检查可用 GPU\n",
        "CHECK_AVALIABLE_GPU = True #@param {type:\"boolean\"}\n",
        "#@markdown - 启用 TCMalloc 内存优化\n",
        "ENABLE_TCMALLOC = True #@param {type:\"boolean\"}\n",
        "#@markdown - 启用 CUDA Malloc 显存优化\n",
        "ENABLE_CUDA_MALLOC = True #@param {type:\"boolean\"}\n",
        "#@markdown - 更新内核\n",
        "UPDATE_CORE = True #@param {type:\"boolean\"}\n",
        "\n",
        "# 预设参数处理\n",
        "SD_TRAINER_REPO = SD_TRAINER_REPO_OPT or SD_TRAINER_BRANCH_PRESET_DICT.get(SD_TRAINER_BRANCH_PRESET).get(\"url\")\n",
        "SD_TRAINER_REQUIREMENTS = SD_TRAINER_REQUIREMENTS_OPT or SD_TRAINER_BRANCH_PRESET_DICT.get(SD_TRAINER_BRANCH_PRESET).get(\"requirements\")\n",
        "SD_TRAINER_LAUNCH_ARGS = SD_TRAINER_LAUNCH_ARGS_OPT or SD_TRAINER_BRANCH_PRESET_DICT.get(SD_TRAINER_BRANCH_PRESET).get(\"launch_args\")\n",
        "SD_TRAINER_WEBUI_PORT = SD_TRAINER_WEBUI_PORT_OPT or SD_TRAINER_BRANCH_PRESET_DICT.get(SD_TRAINER_BRANCH_PRESET).get(\"webui_port\")\n",
        "\n",
        "# @markdown ---\n",
        "##############################################################################\n",
        "# @markdown ## 模型设置, 在安装时将会下载选择的模型：\n",
        "SD_MODEL = []\n",
        "\n",
        "# @markdown - Stable Diffusion 模型\n",
        "v1_5_pruned_emaonly = False # @param  {type:\"boolean\"}\n",
        "animefull_final_pruned = False # @param  {type:\"boolean\"}\n",
        "sd_xl_base_1_0_0_9vae = False # @param  {type:\"boolean\"}\n",
        "sd_xl_refiner_1_0_0_9vae = False # @param  {type:\"boolean\"}\n",
        "sd_xl_turbo_1_0_fp16 = False # @param  {type:\"boolean\"}\n",
        "animagine_xl_3_0_base = False # @param  {type:\"boolean\"}\n",
        "animagine_xl_3_0 = False # @param  {type:\"boolean\"}\n",
        "animagine_xl_3_1 = False # @param  {type:\"boolean\"}\n",
        "animagine_xl_4_0 = False # @param  {type:\"boolean\"}\n",
        "animagine_xl_4_0_opt = False # @param  {type:\"boolean\"}\n",
        "holodayo_xl_2_1 = False # @param  {type:\"boolean\"}\n",
        "kivotos_xl_2_0 = False # @param  {type:\"boolean\"}\n",
        "clandestine_xl_1_0 = False # @param  {type:\"boolean\"}\n",
        "UrangDiffusion_1_1 = False # @param  {type:\"boolean\"}\n",
        "RaeDiffusion_XL_v2 = False # @param  {type:\"boolean\"}\n",
        "kohaku_xl_delta_rev1 = False # @param  {type:\"boolean\"}\n",
        "kohakuXLEpsilon_rev1 = False # @param  {type:\"boolean\"}\n",
        "kohaku_xl_epsilon_rev2 = False # @param  {type:\"boolean\"}\n",
        "kohaku_xl_epsilon_rev3 = False # @param  {type:\"boolean\"}\n",
        "kohaku_xl_zeta = False # @param  {type:\"boolean\"}\n",
        "starryXLV52_v52 = False # @param  {type:\"boolean\"}\n",
        "heartOfAppleXL_v20 = False # @param  {type:\"boolean\"}\n",
        "heartOfAppleXL_v30 = False # @param  {type:\"boolean\"}\n",
        "sanaexlAnimeV10_v10 = False # @param  {type:\"boolean\"}\n",
        "sanaexlAnimeV10_v11 = False # @param  {type:\"boolean\"}\n",
        "SanaeXL_Anime_v1_2_aesthetic = False # @param  {type:\"boolean\"}\n",
        "SanaeXL_Anime_v1_3_aesthetic = False # @param  {type:\"boolean\"}\n",
        "Illustrious_XL_v0_1 = False # @param  {type:\"boolean\"}\n",
        "Illustrious_XL_v0_1_GUIDED = False # @param  {type:\"boolean\"}\n",
        "Illustrious_XL_v1_0 = False # @param  {type:\"boolean\"}\n",
        "Illustrious_XL_v1_1 = False # @param  {type:\"boolean\"}\n",
        "Illustrious_XL_v2_0_stable = False # @param  {type:\"boolean\"}\n",
        "jruTheJourneyRemains_v25XL = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_earlyAccessVersion = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_epsilonPred05Version = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_epsilonPred075 = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_epsilonPred077 = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_epsilonPred10Version = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_epsilonPred11Version = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_vPredTestVersion = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_vPred05Version = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_vPred06Version = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_vPred065SVersion = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_vPred075SVersion = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_vPred09RVersion = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_vPred10Version = True # @param  {type:\"boolean\"}\n",
        "ponyDiffusionV6XL_v6StartWithThisOne = False # @param  {type:\"boolean\"}\n",
        "pdForAnime_v20 = False # @param  {type:\"boolean\"}\n",
        "omegaPonyXLAnime_v20 = False # @param  {type:\"boolean\"}\n",
        "# @markdown - VAE 模型\n",
        "vae_ft_ema_560000_ema_pruned = False # @param  {type:\"boolean\"}\n",
        "vae_ft_mse_840000_ema_pruned = False # @param  {type:\"boolean\"}\n",
        "sdxl_fp16_fix_vae = True # @param  {type:\"boolean\"}\n",
        "\n",
        "\n",
        "# Stable Diffusion 模型\n",
        "v1_5_pruned_emaonly and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sd_1.5/v1-5-pruned-emaonly.safetensors\"})\n",
        "animefull_final_pruned and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sd_1.5/animefull-final-pruned.safetensors\"})\n",
        "sd_xl_base_1_0_0_9vae and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/sd_xl_base_1.0_0.9vae.safetensors\"})\n",
        "sd_xl_refiner_1_0_0_9vae and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/sd_xl_refiner_1.0_0.9vae.safetensors\"})\n",
        "sd_xl_turbo_1_0_fp16 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/sd_xl_turbo_1.0_fp16.safetensors\"})\n",
        "animagine_xl_3_0_base and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/animagine-xl-3.0-base.safetensors\"})\n",
        "animagine_xl_3_0 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/animagine-xl-3.0.safetensors\"})\n",
        "animagine_xl_3_1 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/animagine-xl-3.1.safetensors\"})\n",
        "animagine_xl_4_0 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/animagine-xl-4.0.safetensors\"})\n",
        "animagine_xl_4_0_opt and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/animagine-xl-4.0-opt.safetensors\"})\n",
        "holodayo_xl_2_1 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/holodayo-xl-2.1.safetensors\"})\n",
        "kivotos_xl_2_0 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/kivotos-xl-2.0.safetensors\"})\n",
        "clandestine_xl_1_0 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/clandestine-xl-1.0.safetensors\"})\n",
        "UrangDiffusion_1_1 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/UrangDiffusion-1.1.safetensors\"})\n",
        "RaeDiffusion_XL_v2 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/RaeDiffusion-XL-v2.safetensors\"})\n",
        "kohaku_xl_delta_rev1 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/kohaku-xl-delta-rev1.safetensors\"})\n",
        "kohakuXLEpsilon_rev1 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/kohakuXLEpsilon_rev1.safetensors\"})\n",
        "kohaku_xl_epsilon_rev2 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/kohaku-xl-epsilon-rev2.safetensors\"})\n",
        "kohaku_xl_epsilon_rev3 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/kohaku-xl-epsilon-rev3.safetensors\"})\n",
        "kohaku_xl_zeta and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/kohaku-xl-zeta.safetensors\"})\n",
        "starryXLV52_v52 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/starryXLV52_v52.safetensors\"})\n",
        "heartOfAppleXL_v20 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/heartOfAppleXL_v20.safetensors\"})\n",
        "heartOfAppleXL_v30 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/heartOfAppleXL_v30.safetensors\"})\n",
        "sanaexlAnimeV10_v10 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/sanaexlAnimeV10_v10.safetensors\"})\n",
        "sanaexlAnimeV10_v11 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/sanaexlAnimeV10_v11.safetensors\"})\n",
        "SanaeXL_Anime_v1_2_aesthetic and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/SanaeXL-Anime-v1.2-aesthetic.safetensors\"})\n",
        "SanaeXL_Anime_v1_3_aesthetic and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/SanaeXL-Anime-v1.3-aesthetic.safetensors\"})\n",
        "Illustrious_XL_v0_1 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/Illustrious-XL-v0.1.safetensors\"})\n",
        "Illustrious_XL_v0_1_GUIDED and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/Illustrious-XL-v0.1-GUIDED.safetensors\"})\n",
        "Illustrious_XL_v1_0 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/Illustrious-XL-v1.0.safetensors\"})\n",
        "Illustrious_XL_v1_1 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/Illustrious-XL-v1.1.safetensors\"})\n",
        "Illustrious_XL_v2_0_stable and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/Illustrious-XL-v2.0-stable.safetensors\"})\n",
        "jruTheJourneyRemains_v25XL and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/jruTheJourneyRemains_v25XL.safetensors\"})\n",
        "noobaiXLNAIXL_earlyAccessVersion and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_earlyAccessVersion.safetensors\"})\n",
        "noobaiXLNAIXL_epsilonPred05Version and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_epsilonPred05Version.safetensors\"})\n",
        "noobaiXLNAIXL_epsilonPred075 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_epsilonPred075.safetensors\"})\n",
        "noobaiXLNAIXL_epsilonPred077 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_epsilonPred077.safetensors\"})\n",
        "noobaiXLNAIXL_epsilonPred10Version and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_epsilonPred10Version.safetensors\"})\n",
        "noobaiXLNAIXL_epsilonPred11Version and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_epsilonPred11Version.safetensors\"})\n",
        "noobaiXLNAIXL_vPredTestVersion and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPredTestVersion.safetensors\"})\n",
        "noobaiXLNAIXL_vPred05Version and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred05Version.safetensors\"})\n",
        "noobaiXLNAIXL_vPred06Version and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred06Version.safetensors\"})\n",
        "noobaiXLNAIXL_vPred065SVersion and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred065SVersion.safetensors\"})\n",
        "noobaiXLNAIXL_vPred075SVersion and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred075SVersion.safetensors\"})\n",
        "noobaiXLNAIXL_vPred09RVersion and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred09RVersion.safetensors\"})\n",
        "noobaiXLNAIXL_vPred10Version and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred10Version.safetensors\"})\n",
        "ponyDiffusionV6XL_v6StartWithThisOne and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/ponyDiffusionV6XL_v6StartWithThisOne.safetensors\"})\n",
        "pdForAnime_v20 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/pdForAnime_v20.safetensors\"})\n",
        "omegaPonyXLAnime_v20 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/omegaPonyXLAnime_v20.safetensors\"})\n",
        "# VAE 模型\n",
        "vae_ft_ema_560000_ema_pruned and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-vae/resolve/main/sd_1.5/vae-ft-ema-560000-ema-pruned.safetensors\"})\n",
        "vae_ft_mse_840000_ema_pruned and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-vae/resolve/main/sd_1.5/vae-ft-mse-840000-ema-pruned.safetensors\"})\n",
        "sdxl_fp16_fix_vae and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-vae/resolve/main/sdxl_1.0/sdxl_fp16_fix_vae.safetensors\"})\n",
        "\n",
        "# @markdown ---\n",
        "##############################################################################\n",
        "# @markdown ## 额外挂载目录设置, 在启动时挂载目录到 Google Drive：\n",
        "EXTRA_LINK_DIR = []\n",
        "\n",
        "#@markdown - config_files 目录\n",
        "link_config_files_dir = False # @param {type:\"boolean\"}\n",
        "#@markdown - dataset 目录\n",
        "link_dataset_dir = False # @param {type:\"boolean\"}\n",
        "#@markdown - localizations 目录\n",
        "link_localizations_dir = False # @param {type:\"boolean\"}\n",
        "#@markdown - presets 目录\n",
        "link_presets_dir = False # @param {type:\"boolean\"}\n",
        "\n",
        "\n",
        "link_config_files_dir and EXTRA_LINK_DIR.append({\"link_dir\": \"config_files\"})\n",
        "link_dataset_dir and EXTRA_LINK_DIR.append({\"link_dir\": \"dataset\"})\n",
        "link_localizations_dir and EXTRA_LINK_DIR.append({\"link_dir\": \"localizations\"})\n",
        "link_presets_dir and EXTRA_LINK_DIR.append({\"link_dir\": \"presets\"})\n",
        "\n",
        "##############################################################################\n",
        "\n",
        "INSTALL_PARAMS = {\n",
        "    \"torch_ver\": PYTORCH_VER or None,\n",
        "    \"xformers_ver\": XFORMERS_VER or None,\n",
        "    \"use_uv\": USE_UV,\n",
        "    \"pypi_index_mirror\": PIP_INDEX_MIRROR or None,\n",
        "    \"pypi_extra_index_mirror\": PIP_EXTRA_INDEX_MIRROR or None,\n",
        "    \"pypi_find_links_mirror\": PIP_FIND_LINKS_MIRROR or None,\n",
        "    # Colab 的环境暂不需要以下镜像源\n",
        "    # \"github_mirror\": GITHUB_MIRROR or None,\n",
        "    # \"huggingface_mirror\": HUGGINGFACE_MIRROR or None,\n",
        "    \"pytorch_mirror\": PYTORCH_MIRROR or None,\n",
        "    \"sd_trainer_repo\": SD_TRAINER_REPO or None,\n",
        "    \"sd_trainer_requirements\": SD_TRAINER_REQUIREMENTS or None,\n",
        "    \"model_list\": SD_MODEL,\n",
        "    \"check_avaliable_gpu\": CHECK_AVALIABLE_GPU,\n",
        "    \"enable_tcmalloc\": ENABLE_TCMALLOC,\n",
        "    \"enable_cuda_malloc\": ENABLE_CUDA_MALLOC,\n",
        "    \"custom_sys_pkg_cmd\": None,\n",
        "    \"huggingface_token\": None,\n",
        "    \"modelscope_token\": None,\n",
        "    \"update_core\": UPDATE_CORE,\n",
        "}\n",
        "\n",
        "TUNNEL_PARAMS = {\n",
        "    \"use_ngrok\": USE_NGROK,\n",
        "    \"ngrok_token\": NGROK_TOKEN or None,\n",
        "    \"use_cloudflare\": USE_CLOUDFLARE,\n",
        "    \"use_remote_moe\": USE_REMOTE_MOE,\n",
        "    \"use_localhost_run\": USE_LOCALHOST_RUN,\n",
        "    \"use_gradio\": USE_GRADIO,\n",
        "    \"use_pinggy_io\": USE_PINGGY_IO,\n",
        "    \"use_zrok\": USE_ZROK,\n",
        "    \"zrok_token\": ZROK_TOKEN or None,\n",
        "    \"message\": \"##### SD Trainer 访问地址 #####\",\n",
        "}\n",
        "\n",
        "SD_TRAINER_PATH = \"/content/sd-trainer\"\n",
        "try:\n",
        "    _ = sd_trainer_manager_has_init # type: ignore  # noqa: F821\n",
        "except Exception:\n",
        "    sd_trainer = SDTrainerManager(os.path.dirname(SD_TRAINER_PATH), os.path.basename(SD_TRAINER_PATH), port=int(SD_TRAINER_WEBUI_PORT))\n",
        "    sd_trainer_manager_has_init = True\n",
        "\n",
        "try:\n",
        "    _ = sd_trainer_has_init # type: ignore  # noqa: F821\n",
        "except Exception:\n",
        "    sd_trainer_has_init = False\n",
        "\n",
        "if NO_REPEAT_CONFIGURE_ENV:\n",
        "    if not sd_trainer_has_init:\n",
        "        sd_trainer.install(**INSTALL_PARAMS)\n",
        "        INIT_CONFIG = 1\n",
        "        sd_trainer_has_init = True\n",
        "        CLEAR_LOG and sd_trainer.clear_up()\n",
        "        logger.info(\"SD Trainer 运行环境配置完成\")\n",
        "    else:\n",
        "        logger.info(\"检测到不重复配置环境已启用, 并且在当前 Colab 实例中已配置 SD Trainer 运行环境, 不再重复配置 SD Trainer 运行环境\")\n",
        "        logger.info(\"如需在当前 Colab 实例中重新配置 SD Trainer 运行环境, 请在快速启动选项中取消不重复配置环境功能\")\n",
        "else:\n",
        "    sd_trainer.install(**INSTALL_PARAMS)\n",
        "    INIT_CONFIG = 1\n",
        "    CLEAR_LOG and sd_trainer.clear_up()\n",
        "    logger.info(\"SD Trainer 运行环境配置完成\")\n",
        "\n",
        "LAUNCH_CMD = sd_trainer.get_launch_command(SD_TRAINER_LAUNCH_ARGS)\n",
        "\n",
        "if QUICK_LAUNCH:\n",
        "    logger.info(\"启动 SD Trainer 中\")\n",
        "    os.chdir(SD_TRAINER_PATH)\n",
        "    sd_trainer.check_env(\n",
        "        use_uv=USE_UV,\n",
        "        requirements_file=SD_TRAINER_REQUIREMENTS,\n",
        "    )\n",
        "    sd_trainer.mount_drive(EXTRA_LINK_DIR)\n",
        "    sd_trainer.tun.start_tunnel(**TUNNEL_PARAMS)\n",
        "    logger.info(\"SD Trainer 启动参数: %s\", SD_TRAINER_LAUNCH_ARGS)\n",
        "    !{LAUNCH_CMD}\n",
        "    os.chdir(JUPYTER_ROOT_PATH)\n",
        "    CLEAR_LOG and sd_trainer.clear_up()\n",
        "    logger.info(\"已关闭 SD Trainer\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "ZWnei0cZwWzK"
      },
      "outputs": [],
      "source": [
        "#@title 👇 下载模型（可选）\n",
        "\n",
        "try:\n",
        "    _ = INIT_CONFIG\n",
        "except Exception:\n",
        "    raise Exception(\"未安装 SD Trainer\")\n",
        "\n",
        "#@markdown 选择下载的模型：\n",
        "##############################\n",
        "SD_MODEL = []\n",
        "\n",
        "# @markdown - Stable Diffusion 模型\n",
        "v1_5_pruned_emaonly = False # @param  {type:\"boolean\"}\n",
        "animefull_final_pruned = False # @param  {type:\"boolean\"}\n",
        "sd_xl_base_1_0_0_9vae = False # @param  {type:\"boolean\"}\n",
        "sd_xl_refiner_1_0_0_9vae = False # @param  {type:\"boolean\"}\n",
        "sd_xl_turbo_1_0_fp16 = False # @param  {type:\"boolean\"}\n",
        "animagine_xl_3_0_base = False # @param  {type:\"boolean\"}\n",
        "animagine_xl_3_0 = False # @param  {type:\"boolean\"}\n",
        "animagine_xl_3_1 = False # @param  {type:\"boolean\"}\n",
        "animagine_xl_4_0 = False # @param  {type:\"boolean\"}\n",
        "animagine_xl_4_0_opt = False # @param  {type:\"boolean\"}\n",
        "holodayo_xl_2_1 = False # @param  {type:\"boolean\"}\n",
        "kivotos_xl_2_0 = False # @param  {type:\"boolean\"}\n",
        "clandestine_xl_1_0 = False # @param  {type:\"boolean\"}\n",
        "UrangDiffusion_1_1 = False # @param  {type:\"boolean\"}\n",
        "RaeDiffusion_XL_v2 = False # @param  {type:\"boolean\"}\n",
        "kohaku_xl_delta_rev1 = False # @param  {type:\"boolean\"}\n",
        "kohakuXLEpsilon_rev1 = False # @param  {type:\"boolean\"}\n",
        "kohaku_xl_epsilon_rev2 = False # @param  {type:\"boolean\"}\n",
        "kohaku_xl_epsilon_rev3 = False # @param  {type:\"boolean\"}\n",
        "kohaku_xl_zeta = False # @param  {type:\"boolean\"}\n",
        "starryXLV52_v52 = False # @param  {type:\"boolean\"}\n",
        "heartOfAppleXL_v20 = False # @param  {type:\"boolean\"}\n",
        "heartOfAppleXL_v30 = False # @param  {type:\"boolean\"}\n",
        "sanaexlAnimeV10_v10 = False # @param  {type:\"boolean\"}\n",
        "sanaexlAnimeV10_v11 = False # @param  {type:\"boolean\"}\n",
        "SanaeXL_Anime_v1_2_aesthetic = False # @param  {type:\"boolean\"}\n",
        "SanaeXL_Anime_v1_3_aesthetic = False # @param  {type:\"boolean\"}\n",
        "Illustrious_XL_v0_1 = False # @param  {type:\"boolean\"}\n",
        "Illustrious_XL_v0_1_GUIDED = False # @param  {type:\"boolean\"}\n",
        "Illustrious_XL_v1_0 = False # @param  {type:\"boolean\"}\n",
        "Illustrious_XL_v1_1 = False # @param  {type:\"boolean\"}\n",
        "Illustrious_XL_v2_0_stable = False # @param  {type:\"boolean\"}\n",
        "jruTheJourneyRemains_v25XL = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_earlyAccessVersion = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_epsilonPred05Version = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_epsilonPred075 = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_epsilonPred077 = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_epsilonPred10Version = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_epsilonPred11Version = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_vPredTestVersion = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_vPred05Version = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_vPred06Version = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_vPred065SVersion = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_vPred075SVersion = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_vPred09RVersion = False # @param  {type:\"boolean\"}\n",
        "noobaiXLNAIXL_vPred10Version = False # @param  {type:\"boolean\"}\n",
        "ponyDiffusionV6XL_v6StartWithThisOne = False # @param  {type:\"boolean\"}\n",
        "pdForAnime_v20 = False # @param  {type:\"boolean\"}\n",
        "omegaPonyXLAnime_v20 = False # @param  {type:\"boolean\"}\n",
        "# @markdown - VAE 模型\n",
        "vae_ft_ema_560000_ema_pruned = False # @param  {type:\"boolean\"}\n",
        "vae_ft_mse_840000_ema_pruned = False # @param  {type:\"boolean\"}\n",
        "sdxl_fp16_fix_vae = False # @param  {type:\"boolean\"}\n",
        "\n",
        "\n",
        "# Stable Diffusion 模型\n",
        "v1_5_pruned_emaonly and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sd_1.5/v1-5-pruned-emaonly.safetensors\"})\n",
        "animefull_final_pruned and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sd_1.5/animefull-final-pruned.safetensors\"})\n",
        "sd_xl_base_1_0_0_9vae and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/sd_xl_base_1.0_0.9vae.safetensors\"})\n",
        "sd_xl_refiner_1_0_0_9vae and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/sd_xl_refiner_1.0_0.9vae.safetensors\"})\n",
        "sd_xl_turbo_1_0_fp16 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/sd_xl_turbo_1.0_fp16.safetensors\"})\n",
        "animagine_xl_3_0_base and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/animagine-xl-3.0-base.safetensors\"})\n",
        "animagine_xl_3_0 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/animagine-xl-3.0.safetensors\"})\n",
        "animagine_xl_3_1 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/animagine-xl-3.1.safetensors\"})\n",
        "animagine_xl_4_0 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/animagine-xl-4.0.safetensors\"})\n",
        "animagine_xl_4_0_opt and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/animagine-xl-4.0-opt.safetensors\"})\n",
        "holodayo_xl_2_1 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/holodayo-xl-2.1.safetensors\"})\n",
        "kivotos_xl_2_0 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/kivotos-xl-2.0.safetensors\"})\n",
        "clandestine_xl_1_0 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/clandestine-xl-1.0.safetensors\"})\n",
        "UrangDiffusion_1_1 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/UrangDiffusion-1.1.safetensors\"})\n",
        "RaeDiffusion_XL_v2 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/RaeDiffusion-XL-v2.safetensors\"})\n",
        "kohaku_xl_delta_rev1 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/kohaku-xl-delta-rev1.safetensors\"})\n",
        "kohakuXLEpsilon_rev1 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/kohakuXLEpsilon_rev1.safetensors\"})\n",
        "kohaku_xl_epsilon_rev2 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/kohaku-xl-epsilon-rev2.safetensors\"})\n",
        "kohaku_xl_epsilon_rev3 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/kohaku-xl-epsilon-rev3.safetensors\"})\n",
        "kohaku_xl_zeta and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/kohaku-xl-zeta.safetensors\"})\n",
        "starryXLV52_v52 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/starryXLV52_v52.safetensors\"})\n",
        "heartOfAppleXL_v20 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/heartOfAppleXL_v20.safetensors\"})\n",
        "heartOfAppleXL_v30 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/heartOfAppleXL_v30.safetensors\"})\n",
        "sanaexlAnimeV10_v10 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/sanaexlAnimeV10_v10.safetensors\"})\n",
        "sanaexlAnimeV10_v11 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/sanaexlAnimeV10_v11.safetensors\"})\n",
        "SanaeXL_Anime_v1_2_aesthetic and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/SanaeXL-Anime-v1.2-aesthetic.safetensors\"})\n",
        "SanaeXL_Anime_v1_3_aesthetic and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/SanaeXL-Anime-v1.3-aesthetic.safetensors\"})\n",
        "Illustrious_XL_v0_1 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/Illustrious-XL-v0.1.safetensors\"})\n",
        "Illustrious_XL_v0_1_GUIDED and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/Illustrious-XL-v0.1-GUIDED.safetensors\"})\n",
        "Illustrious_XL_v1_0 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/Illustrious-XL-v1.0.safetensors\"})\n",
        "Illustrious_XL_v1_1 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/Illustrious-XL-v1.1.safetensors\"})\n",
        "Illustrious_XL_v2_0_stable and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/Illustrious-XL-v2.0-stable.safetensors\"})\n",
        "jruTheJourneyRemains_v25XL and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/jruTheJourneyRemains_v25XL.safetensors\"})\n",
        "noobaiXLNAIXL_earlyAccessVersion and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_earlyAccessVersion.safetensors\"})\n",
        "noobaiXLNAIXL_epsilonPred05Version and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_epsilonPred05Version.safetensors\"})\n",
        "noobaiXLNAIXL_epsilonPred075 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_epsilonPred075.safetensors\"})\n",
        "noobaiXLNAIXL_epsilonPred077 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_epsilonPred077.safetensors\"})\n",
        "noobaiXLNAIXL_epsilonPred10Version and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_epsilonPred10Version.safetensors\"})\n",
        "noobaiXLNAIXL_epsilonPred11Version and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_epsilonPred11Version.safetensors\"})\n",
        "noobaiXLNAIXL_vPredTestVersion and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPredTestVersion.safetensors\"})\n",
        "noobaiXLNAIXL_vPred05Version and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred05Version.safetensors\"})\n",
        "noobaiXLNAIXL_vPred06Version and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred06Version.safetensors\"})\n",
        "noobaiXLNAIXL_vPred065SVersion and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred065SVersion.safetensors\"})\n",
        "noobaiXLNAIXL_vPred075SVersion and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred075SVersion.safetensors\"})\n",
        "noobaiXLNAIXL_vPred09RVersion and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred09RVersion.safetensors\"})\n",
        "noobaiXLNAIXL_vPred10Version and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/noobaiXLNAIXL_vPred10Version.safetensors\"})\n",
        "ponyDiffusionV6XL_v6StartWithThisOne and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/ponyDiffusionV6XL_v6StartWithThisOne.safetensors\"})\n",
        "pdForAnime_v20 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/pdForAnime_v20.safetensors\"})\n",
        "omegaPonyXLAnime_v20 and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-model/resolve/main/sdxl_1.0/omegaPonyXLAnime_v20.safetensors\"})\n",
        "# VAE 模型\n",
        "vae_ft_ema_560000_ema_pruned and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-vae/resolve/main/sd_1.5/vae-ft-ema-560000-ema-pruned.safetensors\"})\n",
        "vae_ft_mse_840000_ema_pruned and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-vae/resolve/main/sd_1.5/vae-ft-mse-840000-ema-pruned.safetensors\"})\n",
        "sdxl_fp16_fix_vae and SD_MODEL.append({\"url\": \"https://huggingface.co/licyk/sd-vae/resolve/main/sdxl_1.0/sdxl_fp16_fix_vae.safetensors\"})\n",
        "\n",
        "##############################\n",
        "logger.info(\"下载模型中\")\n",
        "sd_trainer.get_sd_model_from_list(SD_MODEL)\n",
        "CLEAR_LOG and sd_trainer.clear_up()\n",
        "logger.info(\"模型下载完成\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "MbpZVvRMPIAC"
      },
      "outputs": [],
      "source": [
        "#@title 👇 自定义模型下载\n",
        "try:\n",
        "    _ = INIT_CONFIG\n",
        "except Exception:\n",
        "    raise Exception(\"未安装 SD Trainer\")\n",
        "\n",
        "#@markdown ### 填写模型的下载链接：\n",
        "model_url = \"https://huggingface.co/licyk/sd-lora/resolve/main/sdxl/style/CoolFlatColor.safetensors\"  #@param {type:\"string\"}\n",
        "#@markdown ### 填写模型的名称（包括后缀名）：\n",
        "model_name = \"CoolFlatColor.safetensors\"  #@param {type:\"string\"}\n",
        "\n",
        "sd_trainer.get_sd_model(\n",
        "    url=model_url,\n",
        "    filename=model_name or None,\n",
        ")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "cLB6sKhErcG8"
      },
      "outputs": [],
      "source": [
        "#@title 👇 启动 SD Trainer\n",
        "try:\n",
        "    _ = INIT_CONFIG\n",
        "except Exception:\n",
        "    raise Exception(\"未安装 SD Trainer\")\n",
        "\n",
        "logger.info(\"启动 SD Trainer\")\n",
        "os.chdir(SD_TRAINER_PATH)\n",
        "sd_trainer.check_env(\n",
        "    use_uv=USE_UV,\n",
        "    requirements_file=SD_TRAINER_REQUIREMENTS,\n",
        ")\n",
        "sd_trainer.mount_drive(EXTRA_LINK_DIR)\n",
        "sd_trainer.tun.start_tunnel(**TUNNEL_PARAMS)\n",
        "logger.info(\"SD Trainer 启动参数: %s\", SD_TRAINER_LAUNCH_ARGS)\n",
        "!{LAUNCH_CMD}\n",
        "os.chdir(JUPYTER_ROOT_PATH)\n",
        "CLEAR_LOG and sd_trainer.clear_up()\n",
        "logger.info(\"已关闭 SD Trainer\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "AVWoNIEhXy5o"
      },
      "outputs": [],
      "source": [
        "#@title 👇 文件下载工具\n",
        "\n",
        "#@markdown ### 填写文件的下载链接：\n",
        "url = \"\"  #@param {type:\"string\"}\n",
        "#@markdown ### 填写文件的保存路径：\n",
        "file_path = \"/content\"  #@param {type:\"string\"}\n",
        "#@markdown ### 填写文件的保存名称 (可选)：\n",
        "filename = \"\"  #@param {type:\"string\"}\n",
        "\n",
        "sd_trainer.download_file(\n",
        "    url=url,\n",
        "    path=file_path or None,\n",
        "    save_name=filename or None,\n",
        ")\n"
      ]
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "gpuType": "T4",
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.11.8"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
